package com.wd.health.view.activity;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.os.Bundle;
import android.widget.TextView;
import android.widget.Toast;

import com.wd.health.R;
import com.wd.health.model.bean.ByqxqBean;
import com.wd.health.utils.RetrofitManager;
import com.facebook.drawee.view.SimpleDraweeView;

import java.text.SimpleDateFormat;

import io.reactivex.Observer;
import io.reactivex.disposables.Disposable;

public class ByqxqActivity extends AppCompatActivity {

    private TextView tv_byqxq_bz;
    private TextView tv_byqxq_title;
    private TextView tv_byqxq_ks;
    private TextView tv_byqxq_yy;
    private TextView tv_byqxq_time;
    private SimpleDraweeView sdv_byqxq_xgtp;
    private TextView tv_byqxq_zljl;
    private TextView img_byqxq_jy;
    private TextView img_byqxq_sc;
    private TextView tv_byqxq_bzxq;
    private SimpleDateFormat simpleDateFormat=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    private TextView tv_cnyj_name;
    private TextView tv_cnyj_context;
    private TextView tv_cnyj_time;
    private SimpleDraweeView sdv_cnyj_tx;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_byqxq);
        initView();
        initData();
    }

    @Override
    protected void onRestart() {
        super.onRestart();
        initData();
    }

    private void initData() {
        Intent intent = getIntent();
        int id = intent.getIntExtra("id", 0);
        RetrofitManager.getInstance().getByqxqData(id, new Observer<ByqxqBean>() {
            @Override
            public void onSubscribe(Disposable d) {

            }

            @Override
            public void onNext(ByqxqBean byqxqBean) {
                ByqxqBean.ResultBean list = byqxqBean.getResult();
                if (byqxqBean.getStatus().equals("0000")){
                    tv_byqxq_title.setText(list.getTitle());
                    tv_byqxq_bz.setText(list.getDisease());
                    tv_byqxq_ks.setText(list.getDepartment());
                    tv_byqxq_bzxq.setText(list.getDetail());
                    tv_byqxq_yy.setText(list.getTreatmentHospital());
                    long treatmentStartTime = list.getTreatmentStartTime();
                    String format = simpleDateFormat.format(treatmentStartTime);
                    tv_byqxq_time.setText(format);
                    tv_byqxq_zljl.setText(list.getTreatmentProcess());
                    sdv_byqxq_xgtp.setImageURI(list.getPicture());
                    sdv_cnyj_tx.setImageURI(list.getAdoptHeadPic());
                    tv_cnyj_name.setText(list.getAdoptNickName());
                    tv_cnyj_context.setText(list.getAdoptComment());
                    long adoptTime = list.getAdoptTime();
                    String format1 = simpleDateFormat.format(adoptTime);
                    tv_cnyj_time.setText(format1);

                    img_byqxq_sc.setText(list.getCollectionNum()+"");
                    img_byqxq_jy.setText(list.getCommentNum()+"");

                }else {
                    Toast.makeText(ByqxqActivity.this, "该病友圈已被删除", Toast.LENGTH_SHORT).show();
                    finish();
                }
            }

            @Override
            public void onError(Throwable e) {

            }

            @Override
            public void onComplete() {

            }
        });
    }

    private void initView() {
        tv_byqxq_title = findViewById(R.id.tv_byqxq_title);
        tv_byqxq_bz = findViewById(R.id.tv_byqxq_bz);
        tv_byqxq_ks = findViewById(R.id.tv_byqxq_ks);
        tv_byqxq_yy = findViewById(R.id.tv_byqxq_yy);
        tv_byqxq_bzxq = findViewById(R.id.tv_byqxq_bzxq);
        tv_byqxq_time = findViewById(R.id.tv_byqxq_time);
        tv_byqxq_zljl = findViewById(R.id.tv_byqxq_zljl);
        sdv_byqxq_xgtp = findViewById(R.id.sdv_byqxq_xgtp);
        img_byqxq_sc = findViewById(R.id.img_byqxq_sc);
        img_byqxq_jy = findViewById(R.id.img_byqxq_jy);
        tv_cnyj_name = findViewById(R.id.tv_cnyj_name);
        tv_cnyj_time = findViewById(R.id.tv_cnyj_time);
        tv_cnyj_context = findViewById(R.id.tv_cnyj_context);
        sdv_cnyj_tx = findViewById(R.id.sdv_cnyj_tx);
    }
}